﻿using System;
using System.Collections.Generic;
using System.Text;
using Office = Microsoft.Office.Interop;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Text.RegularExpressions;
using System.IO;
using System.Collections;
using System.Globalization;
using System.Diagnostics;
using System.ComponentModel;
using System.Collections.ObjectModel;
using System.Drawing;
using Microsoft.Office.Interop;
using Excel = Microsoft.Office.Interop.Excel;
using System.Windows.Forms;

namespace ReplaceCsv.WallLogParser
{
    partial class ClassExcel
    {

        internal delegate void onChange_Progress(int Maximum, int Current, string Message);
        internal event onChange_Progress _onChange_Progress;

        
        private Excel.Application m_objExcel;
        private Excel.Workbooks m_objBooks;
        private Excel.Workbook m_objBook;
        private Excel.Worksheet m_objWorkSheet;
        private Excel.Sheets m_objSheets;

        private const string m_strDataSheetName = "data";
        private const string m_strResultSheetName = "result";
        private const string m_strPivotTableName = "pivot";
        private const string m_strPivotGraphName = "graph";
        private const string m_strResultRange = "コンテンツ別滞在時間分布";
        private const string m_strResultAvg = "コンテンツ別平均滞在時間";
        private const string m_strResultRank = "コンテンツ別タッチ数ランキング";

        private List<string> m_contentsList;

        private Excel.ChartObjects m_chartObjects;
        private Excel.ChartObject m_chartObject;
        private Excel.Chart m_chart;

        private Color ColorTan_Light = Color.FromArgb(221, 217, 195);
        private Color ColorTan_Medium = Color.FromArgb(197, 190, 151);
        private Color ColorBlue_Light = Color.FromArgb(197, 217, 241);
       

        #region | シートログデータ用 |

        /// <summary>
        /// Excelのシートにログデータを作成
        /// </summary>
        private struct LogDataRow
        {
            //WALL名	サマリー対象時間	コンテンツ名	滞在時間	抽出範囲
            internal string wallName;
            internal string accessTime;
            internal string contentName;
            internal string onTime;
            internal string category; 
        }
        /// <summary>
        /// ログデータを生成する内部メソッド
        /// </summary>
        /// <returns></returns>
        private List<LogDataRow> makeLogSheetData(Dictionary<string,Dictionary<string,List<WallLogBean>>> logs)
        {
            List<LogDataRow> result = new List<LogDataRow>();
            //一旦wall->日時(ファイル名）の順で出力を行う。
            List<string> ar = WallLogTool.getKeyList(logs);
            ar.Sort();
            foreach (string key in ar)
            {
                Dictionary<string, List<WallLogBean>> now = logs[key];
                List<string> fn = WallLogTool.getKeyList(now);
                fn.Sort();
                foreach (string key2 in fn)
                {
                    makeRowDatas(key, now[key2], result);
                }
            }


            return result;
        }
        private void makeRowDatas(string wall, List<WallLogBean> inputList , List<LogDataRow> outList)
        {
            foreach(WallLogBean bean in inputList){
                    outList.Add(getRow(wall, bean));
             }
        }
        private LogDataRow getRow(string wall, WallLogBean bean)
        {
            LogDataRow result = new LogDataRow();
            result.wallName = wall;
            result.accessTime = bean.accessDateTime.ToString("yyyy年MM月dd日 HH時mm分ss秒");
            result.contentName = bean.pageName;
            result.onTime = bean.OnTime.ToString();
            result.category = bean.timeCategory;
            return result;
        }

        #endregion | シートログデータ用 |

        #region  |  Private Procedures  |



        //ここから下がメインのプライベートメソッド
        #region |滞在時間分布のメソッド群|
        /// <summary>
        /// 滞在時間分布の作成
        /// </summary>
        private void createDistributionOntimeSheet()
        {
            int cnt = 0;
            int pos = 1;

            Excel.Worksheet m_objSheet_Result = (Excel.Worksheet)(m_objSheets.Add(Missing.Value, m_objSheets.get_Item(m_objSheets.Count), Missing.Value, Missing.Value));
            m_objSheet_Result.Name = m_strResultRange;

            foreach (string contentsName in m_contentsList)
            {
                Excel.Worksheet m_objSheet_Report_1 = (Excel.Worksheet)(m_objSheets.Add(Missing.Value, m_objSheets.get_Item(m_objSheets.Count), Missing.Value, Missing.Value));
                m_objSheet_Report_1.Name = m_strPivotTableName + "_" + cnt.ToString();
                addPivotTable(m_objWorkSheet, m_objSheet_Report_1, contentsName);

                addPivotChart(m_objSheet_Report_1, contentsName);


                //write result sheet
                m_objSheet_Result.Activate();
                if (cnt % 2 == 0)
                {
                    m_objSheet_Result.Range["A" + pos].Select();

                }
                else
                {
                    m_objSheet_Result.Range["K" + pos].Select();
                    pos = pos + 25;
                }
                m_objSheet_Result.Paste();
                m_objExcel.DisplayAlerts = false;
                m_objSheet_Report_1.Delete();
                cnt = cnt + 1;
            }
        }
        private void addPivotTable(Excel.Worksheet _m_objSheet_Data, Excel.Worksheet _m_objSheet_Report_1, string contentsName)
        {
            //get a reference to the pivot chache
            Excel.PivotCaches pch = m_objBook.PivotCaches();

            //Activate the data sheet before adding the range to the pivot table
            _m_objSheet_Data.Activate();

            Excel.Range rng;
            rng = m_objWorkSheet.get_Range("A65536", m_objExcel.ActiveCell.get_End(Excel.XlDirection.xlDown));
            //MessageBox.Show("最大Rowは" + (65536 - rng.Rows.Count + 1).ToString());
            //wb.Close(false, Type.Missing, Type.Missing);
            //m_objExcel.Quit();

            //add a pivot table reference to the sheet            
            pch.Add(Excel.XlPivotTableSourceType.xlDatabase, "'" + _m_objSheet_Data.Name + "'!A1:'" + _m_objSheet_Data.Name + "'!E" + (65536 - rng.Rows.Count + 1)).CreatePivotTable(_m_objSheet_Report_1.Cells[1, 1], "PivTbl_1", Type.Missing, Type.Missing);
            Excel.PivotTable pvt = _m_objSheet_Report_1.PivotTables("PivTbl_1") as Excel.PivotTable;

            //抽出範囲
            Excel.PivotField fld = ((Excel.PivotField)pvt.PivotFields("抽出範囲"));
            fld.Orientation = Excel.XlPivotFieldOrientation.xlDataField;
            fld.Function = Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlCount;

            //コンテンツ名
            fld = ((Excel.PivotField)pvt.PivotFields("コンテンツ名"));
            fld.Orientation = Excel.XlPivotFieldOrientation.xlRowField;

            fld = ((Excel.PivotField)pvt.PivotFields("コンテンツ名"));
            fld.Orientation = Excel.XlPivotFieldOrientation.xlPageField;

            //WALL名
            fld = ((Excel.PivotField)pvt.PivotFields("WALL名"));
            fld.Orientation = Excel.XlPivotFieldOrientation.xlColumnField;

            //抽出範囲
            fld = ((Excel.PivotField)pvt.PivotFields("抽出範囲"));
            fld.Orientation = Excel.XlPivotFieldOrientation.xlRowField;

            //Filter (Multiple Item Filter)
            Excel.PivotField fld_projectName = ((Excel.PivotField)pvt.PivotFields("コンテンツ名"));
            fld_projectName.Orientation = Excel.XlPivotFieldOrientation.xlPageField;

            //initialize the filter ensuring that all items are checked/selected
            fld_projectName.CurrentPage = contentsName;

            #region |ＣＳＶを出力する際にフィルター直接を行うように削除 20130319 bug|
            ////Excel.PivotFields _PivotFields = (Excel.PivotFields)pvt.get_RowFields(Missing.Value);

            ////foreach (Excel.PivotField _PivotField in _PivotFields)
            ////{
                ////if (string.Compare(_PivotField.Caption, fld.Caption, true) == 0)
                ////{
                    ////Excel.PivotItems _PivotItems = (Excel.PivotItems)_PivotField.PivotItems(Missing.Value);

                    ////foreach (Excel.PivotItem _PivotItem in _PivotItems)
                    ////{
                        ////if (_PivotItem.SourceNameStandard == "(blank)")
                            ////_PivotItem.Visible = false;
                        ////else
                            ////_PivotItem.Visible = true;
                    ////}
                ////}
            ////}

            #endregion |ＣＳＶを出力する際にフィルター直接を行うように削除 20130319 bug|



        }
        private void addPivotChart(Excel.Worksheet _m_objSheet_Report_1, string contentsName)
        {
            Excel.Range _m_objRange_Chart;

            _m_objRange_Chart = _m_objSheet_Report_1.get_Range("A1", "A1");

            m_chartObjects = (Excel.ChartObjects)(_m_objSheet_Report_1.ChartObjects(Missing.Value));
            m_chartObject = m_chartObjects.Add(170, 0, 400, 300);
            m_chart = m_chartObject.Chart;


            m_chart.SetSourceData(_m_objRange_Chart, Excel.XlRowCol.xlColumns);

            m_chart.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xlBarClustered;
            m_chart.HasTitle = true;
            m_chart.ChartTitle.Text = contentsName;
            m_chart.ChartTitle.Font.Size = 12;

            m_chart.ApplyDataLabels(
                Microsoft.Office.Interop.Excel.XlDataLabelsType.xlDataLabelsShowNone
                , Missing.Value, Missing.Value, Missing.Value, Missing.Value, false
                , Missing.Value, true, Missing.Value, Missing.Value);

            m_chartObject.Chart.HasLegend = true;

            m_chart.ChartArea.Copy();

            //_m_objSheet_Report_1.Activate();

        }
        #endregion

        #region |平均滞在時間のグラフ作成メソッド群|
        /// <summary>
        /// コンテンツ別平均滞在時間の作成
        /// </summary>
        private void createAvgSheet()
        {
            //コンテンツ別平均滞在時間
            Excel.Worksheet objSheet_ResultAvg = (Excel.Worksheet)(m_objSheets.Add(Missing.Value, m_objSheets.get_Item(m_objSheets.Count), Missing.Value, Missing.Value));
            objSheet_ResultAvg.Name = m_strResultAvg;

            addPivotTableAverage(m_objWorkSheet, objSheet_ResultAvg);
            addPivotChartAverage(objSheet_ResultAvg);
        }
        private void addPivotTableAverage(Excel.Worksheet _m_objSheet_Data, Excel.Worksheet objSheet_ResultAvg)
        {
            //get a reference to the pivot chache
            Excel.PivotCaches pch = m_objBook.PivotCaches();

            //Activate the data sheet before adding the range to the pivot table
            _m_objSheet_Data.Activate();

            //計算を抑制するものを追加 20130315
            //m_objExcel.Calculation = Excel.XlCalculation.xlCalculationManual;
            //イベントも禁止 20130315
            //m_objExcel.EnableEvents = false;
            //m_objExcel.ScreenUpdating = false;

            Excel.Range rng;
            rng = m_objWorkSheet.get_Range("A65536", m_objExcel.ActiveCell.get_End(Excel.XlDirection.xlDown));

            //add a pivot table reference to the sheet            
            pch.Add(Excel.XlPivotTableSourceType.xlDatabase, "'" + _m_objSheet_Data.Name + "'!A1:'" + _m_objSheet_Data.Name + "'!E" + (65536 - rng.Rows.Count + 1)).CreatePivotTable(objSheet_ResultAvg.Cells[1, 1], "PivTbl_1", Type.Missing, Type.Missing);
            Excel.PivotTable pvt = objSheet_ResultAvg.PivotTables("PivTbl_1") as Excel.PivotTable;

            //コンテンツ名
            Excel.PivotField fld = ((Excel.PivotField)pvt.PivotFields("コンテンツ名"));
            fld.Orientation = Excel.XlPivotFieldOrientation.xlRowField;

            //WALL名
            fld = ((Excel.PivotField)pvt.PivotFields("WALL名"));
            fld.Orientation = Excel.XlPivotFieldOrientation.xlColumnField;

            //滞在時間
            fld = ((Excel.PivotField)pvt.PivotFields("滞在時間"));
            fld.Orientation = Excel.XlPivotFieldOrientation.xlDataField;
            fld.Function = Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlAverage;
            fld.NumberFormat = "[s]";

            //Filter (Multiple Item Filter)
            Excel.PivotField fld_time = ((Excel.PivotField)pvt.PivotFields("滞在時間"));
            fld_time.Orientation = Excel.XlPivotFieldOrientation.xlPageField;

            fld_time.CurrentPage = "(All)";

            Excel.PivotFields _PivotFields = (Excel.PivotFields)pvt.get_PageFields(Missing.Value);

            const string fmt = "H:mm:ss";
            DateTime zeroDateTime = DateTime.ParseExact("0:00:00", fmt, null);
            DateTime maxDateTime = DateTime.ParseExact("0:03:00", fmt, null);


            //foreach (Excel.PivotField _PivotField in _PivotFields)
            //{
            //    if (string.Compare(_PivotField.Caption, fld_time.Caption, true) == 0)
            //    {
            //        Excel.PivotItems _PivotItems = (Excel.PivotItems)_PivotField.PivotItems(Missing.Value);

            //        foreach (Excel.PivotItem _PivotItem in _PivotItems)
            //        {
            //            DateTime dt;
            //            dt = DateTime.ParseExact(_PivotItem.Caption, fmt, null);
            //            if (dt.CompareTo(maxDateTime) > 0)
            //            {
            //                _PivotItem.Visible = false;
            //            }
            //            else if (dt.CompareTo(zeroDateTime) > 0)
            //            {
            //                _PivotItem.Visible = true;
            //            }
            //            else
            //            {
            //                _PivotItem.Visible = false;
            //            }
            //        }
            //    }
            //}
            //計算をもとに戻す 20130315
            //m_objExcel.Calculation = Excel.XlCalculation.xlCalculationAutomatic;
            //イベントも禁止 20130315
            //m_objExcel.EnableEvents = true;
            //m_objExcel.ScreenUpdating = true;
        }
        private void addPivotChartAverage(Excel.Worksheet objSheet_ResultAvg)
        {
            Excel.Range _m_objRange_Chart;

            _m_objRange_Chart = objSheet_ResultAvg.get_Range("A1", "A1");

            m_chartObjects = (Excel.ChartObjects)(objSheet_ResultAvg.ChartObjects(Missing.Value));
            m_chartObject = m_chartObjects.Add(170, 0, 600, 500);
            m_chart = m_chartObject.Chart;


            m_chart.SetSourceData(_m_objRange_Chart, Excel.XlRowCol.xlColumns);

            m_chart.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xlColumnClustered;

            Excel.Axis Xaxis;
            //format the x-axis
            Xaxis = (Excel.Axis)m_chart.Axes(Excel.XlAxisType.xlValue,
                          Excel.XlAxisGroup.xlPrimary);

            Xaxis.MinimumScale = 0;
            Xaxis.MaximumScale = 0.0021;
            Xaxis.MajorUnit = 0.0001736;
            //Xaxis.TickLabels.NumberFormatLocal = "[s]秒";
            Xaxis.TickLabels.NumberFormat = "[s]秒";

            m_chart.ApplyDataLabels(
                Microsoft.Office.Interop.Excel.XlDataLabelsType.xlDataLabelsShowNone
                , Missing.Value, Missing.Value, Missing.Value, Missing.Value, false
                , Missing.Value, true, Missing.Value, Missing.Value);

            m_chartObject.Chart.HasLegend = true;

        }

        #endregion

        #endregion

        #region  |  Internal procedures  |

        /// <summary>
        /// 寺田さんにもらったオープンのほう（あらかじめデータがセットされている前提）
        /// </summary>
        /// <param name="filenName"></param>
        internal void openXLSFile(string fileName)
        {
            m_objExcel = new Excel.Application();
            m_objExcel.Visible = true;
            
            
            m_objBook = m_objExcel.Workbooks.Open(fileName);
            m_objWorkSheet = (Excel.Worksheet)m_objBook.Sheets[1];
            m_objWorkSheet.Select(Type.Missing);

            //get reference to the worksheets
            m_objSheets = (Excel.Sheets)m_objBook.Worksheets;

        }

        /// <summary>
        /// コンテンツ名を取得する、範囲情報をセットする
        /// </summary>
        internal void contentsNameList(List<string> contentsList,string[] rangeArray)
        {
            ////m_contentsList = new List<string>();
            m_contentsList = contentsList;

            m_objExcel.AddCustomList(rangeArray, Missing.Value);

            #region |不要になった処理　コメントアウト|
            //string startPoint = "C2";

            //Excel.Range range = m_objWorkSheet.get_Range(startPoint, Missing.Value);
            //range = range.get_End(Excel.XlDirection.xlDown);
            //string downAddress = range.get_Address(false, false, Excel.XlReferenceStyle.xlA1, Type.Missing, Type.Missing);
            //range = m_objWorkSheet.get_Range(startPoint, downAddress);

            //range.RemoveDuplicates(1);

            //foreach (Excel.Range row in range.Rows)
            //{
            //    Excel.Range cell = (Excel.Range)row.Cells[1, 1];
            //    if (cell.Value2 == null)
            //    {
            //        break;
            //    }
            //    m_contentsList.Add(cell.Value2.ToString());
            //}
            //////m_contentsList.Add("理念");
            //////m_contentsList.Add("リフォーム店検索");
            //////m_contentsList.Add("環境ビジョン");
            //////m_contentsList.Add("大成功の家作り");
            //////m_contentsList.Add("いい住まいって何だろう？");
            //////m_contentsList.Add("お手入れダイアリー");
            //////m_contentsList.Add("お手入れダイアリー/あなたの住まいは今、何歳？");
            //////m_contentsList.Add("インテリア事例集");
            //////m_contentsList.Add("お手入れダイアリー/住まいのメンテナンス");
            //////m_contentsList.Add("お手入れダイアリー/四季のお手入れ");
            #endregion
        }
        /// <summary>
        /// 寺田さんのデータの処理のほう
        /// </summary>
        internal void createWorksheet()
        {
            //step1 滞在時間分布を作成する。
            createDistributionOntimeSheet();
        }
        /// <summary>
        /// 平均滞在時間を作成するほう
        /// </summary>
        internal void createWorksheet2()
        {
            //step2 平均滞在時間を作成する
            createAvgSheet();
        }

        internal void saveWorkBook(FileInfo fi)
        {

            Application.DoEvents();

            m_objExcel.DisplayAlerts = false;

            if (fi.Exists)
                fi.Delete();

            m_objBook.SaveAs(fi.FullName, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, Missing.Value, Missing.Value, Missing.Value, Missing.Value
                , Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);

            if (!m_objExcel.Visible)
                m_objBook.Close(false, Missing.Value, Missing.Value);
        }

        internal void closeApplication()
        {
            if (m_objExcel != null && !m_objExcel.Visible)
            {
                if (m_objExcel != null)
                {
                    m_objExcel.Quit();
                    m_objExcel = null;
                }

                Process[] Processes;

                Processes = Process.GetProcessesByName("EXCEL");
                foreach (Process p in Processes)
                {
                    if (p.MainWindowTitle.Trim() == "")
                        p.Kill();
                }
            }
        }

 

        #endregion


    }
    #region |サンプルたち|
    /// <summary>
    /// サンプルたちを見せないようにするためにパーシャルしたクラス
    /// </summary>
    partial class ClassExcel
    {
        /// <summary>
        /// Struct that defines the data row of the excel sheet
        /// </summary>
        private struct dummyDataRow
        {
            internal int ID;
            internal string projectName;
            internal string targetLanguageName;
            internal int fileWordsTotal;
            internal int fileWordsContextMatch;
            internal int fileWords100p;
            internal int fileWords99_95p;
            internal int fileWords94_85p;
            internal int fileWords84_75p;
            internal int fileWords74_50p;
            internal int fileWords50_0p;
        }
        private List<dummyDataRow> getDummyDataRows()
        {
            #region  |  Setup some dummy data  |

            List<dummyDataRow> dummyDataRows = new List<dummyDataRow>();

            dummyDataRow _dummyDataRow = new dummyDataRow();
            _dummyDataRow.ID = 1;
            _dummyDataRow.projectName = "Proj_1";
            _dummyDataRow.targetLanguageName = "Italian";
            _dummyDataRow.fileWordsTotal = 150;
            _dummyDataRow.fileWordsContextMatch = 0;
            _dummyDataRow.fileWords100p = 25;
            _dummyDataRow.fileWords99_95p = 5;
            _dummyDataRow.fileWords94_85p = 12;
            _dummyDataRow.fileWords84_75p = 10;
            _dummyDataRow.fileWords74_50p = 8;
            _dummyDataRow.fileWords50_0p = 90;
            dummyDataRows.Add(_dummyDataRow);


            _dummyDataRow = new dummyDataRow();
            _dummyDataRow.ID = 2;
            _dummyDataRow.projectName = "Proj_2";
            _dummyDataRow.targetLanguageName = "Italian";
            _dummyDataRow.fileWordsTotal = 176;
            _dummyDataRow.fileWordsContextMatch = 53;
            _dummyDataRow.fileWords100p = 80;
            _dummyDataRow.fileWords99_95p = 0;
            _dummyDataRow.fileWords94_85p = 12;
            _dummyDataRow.fileWords84_75p = 10;
            _dummyDataRow.fileWords74_50p = 18;
            _dummyDataRow.fileWords50_0p = 3;
            dummyDataRows.Add(_dummyDataRow);


            _dummyDataRow = new dummyDataRow();
            _dummyDataRow.ID = 3;
            _dummyDataRow.projectName = "Proj_3";
            _dummyDataRow.targetLanguageName = "Italian";
            _dummyDataRow.fileWordsTotal = 15;
            _dummyDataRow.fileWordsContextMatch = 3;
            _dummyDataRow.fileWords100p = 3;
            _dummyDataRow.fileWords99_95p = 2;
            _dummyDataRow.fileWords94_85p = 0;
            _dummyDataRow.fileWords84_75p = 0;
            _dummyDataRow.fileWords74_50p = 6;
            _dummyDataRow.fileWords50_0p = 1;
            dummyDataRows.Add(_dummyDataRow);

            _dummyDataRow = new dummyDataRow();
            _dummyDataRow.ID = 4;
            _dummyDataRow.projectName = "Proj_4";
            _dummyDataRow.targetLanguageName = "Italian";
            _dummyDataRow.fileWordsTotal = 159;
            _dummyDataRow.fileWordsContextMatch = 6;
            _dummyDataRow.fileWords100p = 3;
            _dummyDataRow.fileWords99_95p = 25;
            _dummyDataRow.fileWords94_85p = 45;
            _dummyDataRow.fileWords84_75p = 10;
            _dummyDataRow.fileWords74_50p = 8;
            _dummyDataRow.fileWords50_0p = 62;
            dummyDataRows.Add(_dummyDataRow);

            #endregion

            return dummyDataRows;
        }

        private void addDataToExcelSheet(Excel.Worksheet _m_objSheet_Data, List<LogDataRow> _dummyDataRows)
        {
            //setup a row index counter for the data sheet
            int CurrentRowIndex_Data = 1;


            #region  |  Insert Data Header Row Example  |


            ////if (_onChange_Progress != null)
            ////    _onChange_Progress(_dummyDataRows.Count, CurrentRowIndex_Data, "Inserting data headers");

            Excel.Range m_objRange_header;
            //////////////////////
            //セルのデータを書き込むところから、、、20130313 ペンディング
            /////////////////////
            //まずはヘッダーを書き込み、、いったんシンプルにしてしまう。。。

            m_objRange_header = _m_objSheet_Data.get_Range("A" + CurrentRowIndex_Data, Missing.Value);
            m_objRange_header.Value2 = "WALL名";
            m_objRange_header.WrapText = false;
            m_objRange_header.ColumnWidth = 12;
            m_objRange_header.Cells.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
            m_objRange_header.Cells.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
            m_objRange_header.Font.Bold = true;
            m_objRange_header.BorderAround(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlThin,
            Excel.XlColorIndex.xlColorIndexAutomatic, Missing.Value);
            m_objRange_header.Interior.Color = System.Drawing.ColorTranslator.ToOle(ColorTan_Medium);


            m_objRange_header = _m_objSheet_Data.get_Range("B" + CurrentRowIndex_Data, Missing.Value);
            m_objRange_header.Value2 = "サマリー対象時間";
            m_objRange_header.WrapText = false;
            m_objRange_header.ColumnWidth = 12;
            m_objRange_header.Cells.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
            m_objRange_header.Cells.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
            m_objRange_header.Font.Bold = true;
            m_objRange_header.BorderAround(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlThin,
            Excel.XlColorIndex.xlColorIndexAutomatic, Missing.Value);
            m_objRange_header.Interior.Color = System.Drawing.ColorTranslator.ToOle(ColorTan_Medium);


            m_objRange_header = _m_objSheet_Data.get_Range("C" + CurrentRowIndex_Data, Missing.Value);
            m_objRange_header.Value2 = "コンテンツ名";
            m_objRange_header.WrapText = false;
            m_objRange_header.ColumnWidth = 12;
            m_objRange_header.Cells.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
            m_objRange_header.Cells.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
            m_objRange_header.Font.Bold = true;
            m_objRange_header.BorderAround(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlThin,
            Excel.XlColorIndex.xlColorIndexAutomatic, Missing.Value);
            m_objRange_header.Interior.Color = System.Drawing.ColorTranslator.ToOle(ColorTan_Medium);


            m_objRange_header = _m_objSheet_Data.get_Range("D" + CurrentRowIndex_Data, Missing.Value);
            m_objRange_header.Value2 = "滞在時間";
            m_objRange_header.WrapText = false;
            m_objRange_header.ColumnWidth = 12;
            m_objRange_header.Cells.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
            m_objRange_header.Cells.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
            m_objRange_header.Font.Bold = true;
            m_objRange_header.BorderAround(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlThin,
            Excel.XlColorIndex.xlColorIndexAutomatic, Missing.Value);
            m_objRange_header.Interior.Color = System.Drawing.ColorTranslator.ToOle(ColorTan_Medium);

            m_objRange_header = _m_objSheet_Data.get_Range("E" + CurrentRowIndex_Data, Missing.Value);
            m_objRange_header.Value2 = "抽出範囲";
            m_objRange_header.WrapText = false;
            m_objRange_header.ColumnWidth = 12;
            m_objRange_header.Cells.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
            m_objRange_header.Cells.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
            m_objRange_header.Font.Bold = true;
            m_objRange_header.BorderAround(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlThin,
            Excel.XlColorIndex.xlColorIndexAutomatic, Missing.Value);
            m_objRange_header.Interior.Color = System.Drawing.ColorTranslator.ToOle(ColorTan_Medium);

            ////m_objRange_header = _m_objSheet_Data.get_Range("F" + CurrentRowIndex_Data, Missing.Value);
            ////m_objRange_header.Value2 = "Words (99-95)";
            ////m_objRange_header.WrapText = false;
            ////m_objRange_header.ColumnWidth = 12;
            ////m_objRange_header.Cells.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
            ////m_objRange_header.Cells.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
            ////m_objRange_header.Font.Bold = true;
            ////m_objRange_header.BorderAround(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlThin,
            ////Excel.XlColorIndex.xlColorIndexAutomatic, Missing.Value);
            ////m_objRange_header.Interior.Color = System.Drawing.ColorTranslator.ToOle(ColorTan_Medium);

            ////m_objRange_header = _m_objSheet_Data.get_Range("G" + CurrentRowIndex_Data, Missing.Value);
            ////m_objRange_header.Value2 = "Words (94-85)";
            ////m_objRange_header.WrapText = false;
            ////m_objRange_header.ColumnWidth = 12;
            ////m_objRange_header.Cells.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
            ////m_objRange_header.Cells.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
            ////m_objRange_header.Font.Bold = true;
            ////m_objRange_header.BorderAround(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlThin,
            ////Excel.XlColorIndex.xlColorIndexAutomatic, Missing.Value);
            ////m_objRange_header.Interior.Color = System.Drawing.ColorTranslator.ToOle(ColorTan_Medium);


            ////m_objRange_header = _m_objSheet_Data.get_Range("H" + CurrentRowIndex_Data, Missing.Value);
            ////m_objRange_header.Value2 = "Words (84-75)";
            ////m_objRange_header.WrapText = false;
            ////m_objRange_header.ColumnWidth = 12;
            ////m_objRange_header.Cells.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
            ////m_objRange_header.Cells.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
            ////m_objRange_header.Font.Bold = true;
            ////m_objRange_header.BorderAround(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlThin,
            ////Excel.XlColorIndex.xlColorIndexAutomatic, Missing.Value);
            ////m_objRange_header.Interior.Color = System.Drawing.ColorTranslator.ToOle(ColorTan_Medium);

            ////m_objRange_header = _m_objSheet_Data.get_Range("I" + CurrentRowIndex_Data, Missing.Value);
            ////m_objRange_header.Value2 = "Words (74-50)";
            ////m_objRange_header.WrapText = false;
            ////m_objRange_header.ColumnWidth = 12;
            ////m_objRange_header.Cells.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
            ////m_objRange_header.Cells.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
            ////m_objRange_header.Font.Bold = true;
            ////m_objRange_header.BorderAround(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlThin,
            ////Excel.XlColorIndex.xlColorIndexAutomatic, Missing.Value);
            ////m_objRange_header.Interior.Color = System.Drawing.ColorTranslator.ToOle(ColorTan_Medium);

            ////m_objRange_header = _m_objSheet_Data.get_Range("J" + CurrentRowIndex_Data, Missing.Value);
            ////m_objRange_header.Value2 = "Words (50-0)";
            ////m_objRange_header.WrapText = false;
            ////m_objRange_header.ColumnWidth = 12;
            ////m_objRange_header.Cells.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
            ////m_objRange_header.Cells.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
            ////m_objRange_header.Font.Bold = true;
            ////m_objRange_header.BorderAround(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlThin,
            ////Excel.XlColorIndex.xlColorIndexAutomatic, Missing.Value);
            ////m_objRange_header.Interior.Color = System.Drawing.ColorTranslator.ToOle(ColorTan_Medium);




            #endregion

            #region  |  Insert Data Row Example  |

            Excel.Range m_objRange_data;


            foreach (LogDataRow _DataRow in _dummyDataRows)
            {

                CurrentRowIndex_Data++;

                /////if (_onChange_Progress != null)
                ////    _onChange_Progress(_dummyDataRows.Count, CurrentRowIndex_Data, "Inserting data rows");

                m_objRange_data = _m_objSheet_Data.get_Range("A" + CurrentRowIndex_Data, Missing.Value);
                m_objRange_data.Value2 = _DataRow.wallName;
                m_objRange_data.WrapText = false;
                ////m_objRange_data.NumberFormat = @"@";
                m_objRange_data.Cells.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
                m_objRange_data.Interior.ColorIndex = 0;

                m_objRange_data = _m_objSheet_Data.get_Range("B" + CurrentRowIndex_Data, Missing.Value);
                m_objRange_data.Value2 = _DataRow.accessTime;
                m_objRange_data.WrapText = false;
                ////m_objRange_data.NumberFormat = @"@";
                m_objRange_data.Cells.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
                m_objRange_data.Interior.ColorIndex = 0;

                m_objRange_data = _m_objSheet_Data.get_Range("C" + CurrentRowIndex_Data, Missing.Value);
                m_objRange_data.Value2 = _DataRow.contentName;
                m_objRange_data.WrapText = false;
                ////m_objRange_data.NumberFormat = @"#,##0";
                m_objRange_data.Cells.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
                m_objRange_data.Interior.ColorIndex = 0;


                m_objRange_data = _m_objSheet_Data.get_Range("D" + CurrentRowIndex_Data, Missing.Value);
                m_objRange_data.Value2 = _DataRow.onTime;
                m_objRange_data.WrapText = false;
                //m_objRange_data.NumberFormat = @"#,##0";
                m_objRange_data.Cells.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
                m_objRange_data.Interior.ColorIndex = 0;

                m_objRange_data = _m_objSheet_Data.get_Range("E" + CurrentRowIndex_Data, Missing.Value);
                m_objRange_data.Value2 = _DataRow.category;
                m_objRange_data.WrapText = false;
                //m_objRange_data.NumberFormat = @"#,##0";
                m_objRange_data.Cells.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
                m_objRange_data.Interior.ColorIndex = 0;

                ////m_objRange_data = _m_objSheet_Data.get_Range("F" + CurrentRowIndex_Data, Missing.Value);
                ////m_objRange_data.Value2 = _DataRow.fileWords99_95p;
                ////m_objRange_data.WrapText = false;
                ////m_objRange_data.NumberFormat = @"#,##0";
                ////m_objRange_data.Cells.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
                ////m_objRange_data.Interior.ColorIndex = 0;

                ////m_objRange_data = _m_objSheet_Data.get_Range("G" + CurrentRowIndex_Data, Missing.Value);
                ////m_objRange_data.Value2 = _DataRow.fileWords94_85p;
                ////m_objRange_data.WrapText = false;
                ////m_objRange_data.NumberFormat = @"#,##0";
                ////m_objRange_data.Cells.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
                ////m_objRange_data.Interior.ColorIndex = 0;

                ////m_objRange_data = _m_objSheet_Data.get_Range("H" + CurrentRowIndex_Data, Missing.Value);
                ////m_objRange_data.Value2 = _DataRow.fileWords84_75p;
                ////m_objRange_data.WrapText = false;
                ////m_objRange_data.NumberFormat = @"#,##0";
                ////m_objRange_data.Cells.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
                ////m_objRange_data.Interior.ColorIndex = 0;

                ////m_objRange_data = _m_objSheet_Data.get_Range("I" + CurrentRowIndex_Data, Missing.Value);
                ////m_objRange_data.Value2 = _DataRow.fileWords74_50p;
                ////m_objRange_data.WrapText = false;
                ////m_objRange_data.NumberFormat = @"#,##0";
                ////m_objRange_data.Cells.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
                ////m_objRange_data.Interior.ColorIndex = 0;

                ////m_objRange_data = _m_objSheet_Data.get_Range("J" + CurrentRowIndex_Data, Missing.Value);
                ////m_objRange_data.Value2 = _DataRow.fileWords50_0p;
                ////m_objRange_data.WrapText = false;
                ////m_objRange_data.NumberFormat = @"#,##0";
                ////m_objRange_data.Cells.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
                ////m_objRange_data.Interior.ColorIndex = 0;


            }



            #endregion

            #region  |  Perform some formating on the datarange  |

            //Exmaple of formatting the datarage after you have finished inserting the data

            //Note: it is quicker to perform the majority of the formatting after
            //you have finished inserting the data.

            Excel.Range m_objRange = _m_objSheet_Data.get_Range("A2", "J" + CurrentRowIndex_Data);
            m_objRange.Font.Name = m_objExcel.StandardFont;
            m_objRange.Font.Size = m_objExcel.StandardFontSize;
            m_objRange.Font.Bold = false;
            m_objRange.BorderAround(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlThin,
            Excel.XlColorIndex.xlColorIndexAutomatic, Missing.Value);

            #endregion
        }

        private void addPivotTableSample(Excel.Worksheet _m_objSheet_Data, Excel.Worksheet _m_objSheet_Report_1)
        {
            #region  |  Pivot Table  |


            if (_onChange_Progress != null)
                _onChange_Progress(1, 1, "Adding pivot table...");


            //get a reference to the pivot chache
            Excel.PivotCaches pch = m_objBook.PivotCaches();

            //Activate the data sheet before adding the range to the pivot table
            _m_objSheet_Data.Activate();

            //add a pivot table reference to the sheet            
            pch.Add(Excel.XlPivotTableSourceType.xlDatabase, "'" + _m_objSheet_Data.Name + "'!A1:'" + _m_objSheet_Data.Name + "'!J5").CreatePivotTable(_m_objSheet_Report_1.Cells[1, 1], "PivTbl_1", Type.Missing, Type.Missing);
            Excel.PivotTable pvt = _m_objSheet_Report_1.PivotTables("PivTbl_1") as Excel.PivotTable;




            //Data
            Excel.PivotField fld = ((Excel.PivotField)pvt.PivotFields("Context Matches"));
            fld.Orientation = Excel.XlPivotFieldOrientation.xlDataField;
            fld.Function = Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum;
            fld.NumberFormat = "#,##0_);[Red](#,##0)";

            //Data
            fld = ((Excel.PivotField)pvt.PivotFields("Words (100)"));
            fld.Orientation = Excel.XlPivotFieldOrientation.xlDataField;
            fld.Function = Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum;
            fld.NumberFormat = "#,##0_);[Red](#,##0)";

            //Data
            fld = ((Excel.PivotField)pvt.PivotFields("Words (99-95)"));
            fld.Orientation = Excel.XlPivotFieldOrientation.xlDataField;
            fld.Function = Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum;
            fld.NumberFormat = "#,##0_);[Red](#,##0)";

            //Data
            fld = ((Excel.PivotField)pvt.PivotFields("Words (94-85)"));
            fld.Orientation = Excel.XlPivotFieldOrientation.xlDataField;
            fld.Function = Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum;
            fld.NumberFormat = "#,##0_);[Red](#,##0)";

            //Data
            fld = ((Excel.PivotField)pvt.PivotFields("Words (84-75)"));
            fld.Orientation = Excel.XlPivotFieldOrientation.xlDataField;
            fld.Function = Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum;
            fld.NumberFormat = "#,##0_);[Red](#,##0)";

            //Data
            fld = ((Excel.PivotField)pvt.PivotFields("Words (74-50)"));
            fld.Orientation = Excel.XlPivotFieldOrientation.xlDataField;
            fld.Function = Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum;
            fld.NumberFormat = "#,##0_);[Red](#,##0)";

            //Data
            fld = ((Excel.PivotField)pvt.PivotFields("Words (50-0)"));
            fld.Orientation = Excel.XlPivotFieldOrientation.xlDataField;
            fld.Function = Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum;
            fld.NumberFormat = "#,##0_);[Red](#,##0)";


            //Filter (Single Item Filter)
            Excel.PivotField fld_targetLanguage = ((Excel.PivotField)pvt.PivotFields("Target Language"));
            fld_targetLanguage.Orientation = Excel.XlPivotFieldOrientation.xlPageField;
            fld_targetLanguage.CurrentPage = "Italian";



            //Filter (Multiple Item Filter)
            Excel.PivotField fld_projectName = ((Excel.PivotField)pvt.PivotFields("Project Name"));
            fld_projectName.Orientation = Excel.XlPivotFieldOrientation.xlPageField;

            //fld_projectName.CubeField.EnableMultiplePageItems

            //dummy filter list that we want to apply on the data
            List<string> ListToFilter = new List<string>();
            ListToFilter.Add("Proj_1");
            ListToFilter.Add("Proj_2");



            //initialize the filter ensuring that all items are checked/selected
            fld_projectName.CurrentPage = "(All)";


            //Apply the 'Multiple Items' filter on the pivot table.
            //
            //This should resemble the same functionality as manullay 
            //checking the checkbox for 'Select Multiple Items'
            //and then selecting multiple items for the filter.
            Excel.PivotFields _PivotFields = (Excel.PivotFields)pvt.get_PageFields(Missing.Value);

            foreach (Excel.PivotField _PivotField in _PivotFields)
            {
                if (string.Compare(_PivotField.Caption, fld_projectName.Caption, true) == 0)
                {
                    Excel.PivotItems _PivotItems = (Excel.PivotItems)_PivotField.PivotItems(Missing.Value);

                    foreach (Excel.PivotItem _PivotItem in _PivotItems)
                    {
                        //Note: only the filter items whose items match ("Proj_1, Proj_2") 
                        //will be checked/selected
                        if (ListToFilter.Contains(_PivotItem.Caption))
                            _PivotItem.Visible = true;
                        else
                            _PivotItem.Visible = false;
                    }
                }
            }



            //define how the xlDataField values are aligned
            pvt.DataPivotField.Orientation = Excel.XlPivotFieldOrientation.xlRowField;




            #endregion
        }
        private void addPivotChartSample(Excel.Worksheet _m_objSheet_Report_1)
        {
            #region  |  Chart Object  |

            if (_onChange_Progress != null)
                _onChange_Progress(1, 1, "Adding pivot chart...");

            Excel.Range _m_objRange_Chart;

            //Ensure that the Pivot Table has focus; then the chart object will automatically inherit the reference.
            _m_objRange_Chart = _m_objSheet_Report_1.get_Range("A1", "A1");
            //_m_objRange_Chart.Activate();


            //Add the new chart object and have fun :-)
            Excel.ChartObjects _ChartObjects = (Excel.ChartObjects)(_m_objSheet_Report_1.ChartObjects(Missing.Value));
            Excel.ChartObject _ChartObject = _ChartObjects.Add(170, 0, 400, 300);
            Excel.Chart _Chart = _ChartObject.Chart;


            _Chart.SetSourceData(_m_objRange_Chart, Excel.XlRowCol.xlColumns);

            _Chart.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xl3DPieExploded;
            _Chart.HasTitle = true;
            _Chart.ChartTitle.Text = "Italian Word Count % - Example";
            _Chart.ChartTitle.Font.Size = 12;

            _Chart.ApplyDataLabels(
                Microsoft.Office.Interop.Excel.XlDataLabelsType.xlDataLabelsShowNone
                , Missing.Value, Missing.Value, Missing.Value, Missing.Value, false
                , Missing.Value, true, Missing.Value, Missing.Value);


            _Chart.Rotation = 0; //X
            _Chart.Elevation = 60; //Y
            _Chart.Perspective = 10; //Perspective
            _Chart.DepthPercent = 100; //Depth

            _ChartObject.Chart.HasLegend = true;

            _m_objSheet_Report_1.Activate();

            #endregion
        }

        /// <summary>
        /// こっちのメソッドはたぶんもう誓わない
        /// </summary>
        /// <param name="fileName"></param>
        internal void openXLSFilex(string fileName)
        {

            m_objExcel = new Excel.Application();
            //set some default values
            //m_objExcel.Visible = isVisible;
            m_objExcel.Visible = true;
            m_objExcel.StandardFont = "Arial";
            m_objExcel.StandardFontSize = 10;

            //get a reference to the Excel workbooks
            m_objBooks = (Excel.Workbooks)m_objExcel.Workbooks;

            //add a new workbook
            m_objBooks.GetType().InvokeMember("Add", BindingFlags.InvokeMethod, null, m_objBooks, null, Application.CurrentCulture);
            m_objBook = (Excel.Workbook)(m_objBooks.get_Item(1));

            //get reference to the worksheets
            m_objSheets = (Excel.Sheets)m_objBook.Worksheets;

            //Remove all but 1 sheet
            //Note: the work book adds 3 sheets by default; this simply removes the surplus sheets
            for (int i = (m_objSheets.Count - 1); i > 0; i--)
            {
                Excel.Worksheet m_objSheet = (Excel.Worksheet)(m_objSheets.get_Item(i));
                m_objSheet.Delete();
            }




            ////m_objExcel.Visible = true;
            ////m_objBook = m_objExcel.Workbooks.Open(fileName);
            ////m_objWorkSheet = (Excel.Worksheet)m_objBook.Sheets[1];
            ////m_objWorkSheet.Select(Type.Missing);

            //get reference to the worksheets
            m_objSheets = (Excel.Sheets)m_objBook.Worksheets;
            //Excel.Range rng;
            //rng = ws1.get_Range("A65536", m_objExcel.ActiveCell.get_End(Excel.XlDirection.xlDown));
            //MessageBox.Show("最大Rowは" + (65536 - rng.Rows.Count + 1).ToString());
            //wb.Close(false, Type.Missing, Type.Missing);
            //m_objExcel.Quit();



            //Excel.Range rng;

            //m_objExcel = new Excel.Application();
            //m_objExcel.Visible = false;
            //Excel.Workbook wb = m_objExcel.Workbooks.Open(fileName);

            //Excel.Worksheet ws1 = wb.Sheets[1];
            //ws1.Select(Type.Missing);
            //rng = ws1.get_Range("A65536", m_objExcel.ActiveCell.get_End(Excel.XlDirection.xlDown));
            //MessageBox.Show("最大Rowは" + (65536 - rng.Rows.Count + 1).ToString());

            //wb.Close(false, Type.Missing, Type.Missing);
            //m_objExcel.Quit(); 



        }
        internal void createNewXLSFile(bool isVisible)
        {
            //get a reference to the interop
            m_objExcel = new Excel.Application();

            //set some default values
            m_objExcel.Visible = isVisible;
            m_objExcel.StandardFont = "Arial";
            m_objExcel.StandardFontSize = 10;

            //get a reference to the Excel workbooks
            m_objBooks = (Excel.Workbooks)m_objExcel.Workbooks;

            //add a new workbook
            m_objBooks.GetType().InvokeMember("Add", BindingFlags.InvokeMethod, null, m_objBooks, null, Application.CurrentCulture);
            m_objBook = (Excel.Workbook)(m_objBooks.get_Item(1));

            //get reference to the worksheets
            m_objSheets = (Excel.Sheets)m_objBook.Worksheets;

            //Remove all but 1 sheet
            //Note: the work book adds 3 sheets by default; this simply removes the surplus sheets
            for (int i = (m_objSheets.Count - 1); i > 0; i--)
            {
                Excel.Worksheet m_objSheet = (Excel.Worksheet)(m_objSheets.get_Item(i));
                m_objSheet.Delete();
            }
        }


        /// <summary>
        /// サンプルの方だが、もうたぶん使わない
        /// </summary>
        /// <param name="logList"></param>
        internal void createWorksheet(Dictionary<string, Dictionary<string, List<WallLogBean>>> logList)
        {
            int cnt = 0;
            int pos = 1;



            //Create a new worksheet to hold the data
            Excel.Worksheet m_objSheet_Data = (Excel.Worksheet)(m_objSheets.get_Item((1)));
            m_objSheet_Data.Name = "Data";
            m_objExcel.ActiveWindow.DisplayGridlines = false;

            //Create a dummydatarow list to populate the excel sheet
            List<LogDataRow> dummyDataRows = makeLogSheetData(logList);

            //まずはデータを当てはめることからスタート
            //Add the data rows to the excel sheet
            addDataToExcelSheet(m_objSheet_Data, dummyDataRows);



            //Create a new worksheet to hold the pivot tabel and chart
            ////////Excel.Worksheet m_objSheet_Report_1 = (Excel.Worksheet)(m_objSheets.Add(Missing.Value, m_objSheets.get_Item(m_objSheets.Count), Missing.Value, Missing.Value));
            ////////m_objSheet_Report_1.Name = "Report Example 1";






            Excel.Worksheet m_objSheet_Result = (Excel.Worksheet)(m_objSheets.Add(Missing.Value, m_objSheets.get_Item(m_objSheets.Count), Missing.Value, Missing.Value));
            m_objSheet_Result.Name = m_strResultRange;

            foreach (string contentsName in m_contentsList)
            {
                Excel.Worksheet m_objSheet_Report_1 = (Excel.Worksheet)(m_objSheets.Add(Missing.Value, m_objSheets.get_Item(m_objSheets.Count), Missing.Value, Missing.Value));
                m_objSheet_Report_1.Name = m_strPivotTableName + "_" + cnt.ToString();
                addPivotTable(m_objWorkSheet, m_objSheet_Report_1, contentsName);

                addPivotChart(m_objSheet_Report_1, contentsName);


                //write result sheet
                m_objSheet_Result.Activate();
                if (cnt % 2 == 0)
                {
                    m_objSheet_Result.Range["A" + pos].Select();

                }
                else
                {
                    m_objSheet_Result.Range["K" + pos].Select();
                    pos = pos + 25;
                }
                m_objSheet_Result.Paste();
                m_objExcel.DisplayAlerts = false;
                m_objSheet_Report_1.Delete();
                cnt = cnt + 1;
            }
        }
    }
    #endregion |サンプルたち|

}


